window.onload=function(){        
	
	var btn01=document.getElementById("btn01");
	btn01.onclick=function(){
		var pwd=form1.pwd.value;
		
		var account=form1.account.value;
		
		if(account==""){
			alert("请输入账号");
			account.focus();
			return;
		}
		
		if(form1.pwds.value==""){
			alert("请输入密码");
			form1.pwd.focus();
			return;
		}
		if(form1.pwd.value.length<6){
			alert("请输入6位数密码");
			form1.pwd.focus();
			return;
		}
		if(form1.pwds.value!=pwd){
			alert("两次输入的密码不一致，请重新输入");
			form1.pwds.focus();
			return;
		}
		
		
		
		var phone=form1.phone.value;
		
		if(phone==""){
			alert("请输入手机号");
			phone.focus();
			return;
		}
		if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))){ 
			
	        alert("手机号格式不对,请重新输入"); 
	       
	        return ; 
	  	} 
		
		form1.pwd.value =  hex_md5(pwd);
		
		
		
		form1.submit();
	}
	/**
	 * 账户输入失去焦点触发
	 */
	form1.account.onblur=function(){
				
		var account=form1.account.value;
			
		if(account==""){
			alert("请输入账号");
				
			return;
		}
			
			var url="/J54Books/queryUser?account="+account;
			
			var req=new XMLHttpRequest();
			
			req.open("GET",url);
			
			req.send(null);
			
			req.onreadystatechange=function(){
				
				if(req.readyState==4){
					
					if((req.status==200||req.status==304)){
						
						
						//将返回的结果使用文本节点接收
						var ponse=document.createTextNode(req.response);
						
						var account=document.getElementsByName("account")[0];
										
						//使用父节点替换节点
						form1.replaceChild(ponse , account.nextSibling);
						
					}
				}
			}
				
	}
	/**
	 * 密码输入失去焦点触发
	 */	
	form1.pwd.onblur=function(){
				
		if(form1.pwd.value==""){
			alert("请输入密码");
				
			return;
		}
		if(form1.pwd.value.length<6){
				
			alert("请输入6位数密码");
				
			return;
		}
			
			
		}
	/**
	 * 验证密码失去焦点触发
	 */
		form1.pwds.onblur=function(){
				var pwd=form1.pwd.value;
				var pwds=form1.pwds.value;
				
			if(pwds==""){
				alert("请输入验证密码");
				
				return;
			}
			//比较两次输入的密码是否一致
			if(pwds!=pwd){
				alert("两次输入的密码不一致，请重新输入");
				var pwds1=document.getElementsByName("pwds")[0];
				pwds1.value = "";
				return;
			}
			
			
			
		}
		/**
		 * 手机号输入失去焦点触发
		 */
		form1.phone.onblur=function(){
				
			var phone=form1.phone.value;
			
			if(phone==""){
				alert("请输入手机号");
				
				return;
			}
			if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))){ 
				
		        alert("手机号格式不对,请重新输入"); 
		        var phone1=document.getElementsByName("phone")[0];
		        phone1.value = "";
		        
		        return ; 
		  	} 
			
			var url="/J54Books/queryPhone?phone="+phone;
			
			var req=new XMLHttpRequest();
			
			req.open("GET",url);
			
			req.send(null);
			
			req.onreadystatechange=function(){
				
				if(req.readyState==4){
					
					if(req.status==200||req.status==304){
						
						if(req.response=="手机号已存在"){
							  var phone1=document.getElementsByName("phone")[0];
						        phone1.value = "";
						}
						
						//将返回的结果使用文本节点接收
						var ponse=document.createTextNode(req.response);
						
						var phone=document.getElementsByName("phone")[0];
										
						//使用父节点替换节点
						form1.replaceChild(ponse , phone.nextSibling);
						
						
						
					}
				}
			}
			
			
		}
	
}